package com.elow.testffmpeg.Demo2;

import android.content.Context;
import android.opengl.GLSurfaceView;

import com.elow.testffmpeg.MyGLRenderer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

public class MyView extends GLSurfaceView {
    public MyView(Context context) {
        super(context);
        init();
    }

    private void init()
    {
        MyRenderer myGLRenderer = new MyRenderer();
        this.setRenderer(myGLRenderer);
        setRenderMode(RENDERMODE_CONTINUOUSLY);//设置渲染模式为主动渲染
    }

    private class MyRenderer implements Renderer{

        private Dian dian;

        @Override
        public void onSurfaceCreated(GL10 gl10, EGLConfig eglConfig) {
            gl10.glClearColor(0,1,1,1);

            dian = new Dian();
        }

        @Override
        public void onSurfaceChanged(GL10 gl, int width, int height) {
            gl.glViewport(0,0,width,height);
            gl.glMatrixMode(GL10.GL_PROJECTION);
            gl.glLoadIdentity();
            float r = (float)width/height;
            gl.glFrustumf(-r,r,-1,1,1,20);
        }

        @Override
        public void onDrawFrame(GL10 gl) {

            gl.glClear(GL10.GL_DEPTH_BUFFER_BIT|GL10.GL_COLOR_BUFFER_BIT);
            gl.glMatrixMode(GL10.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glTranslatef(0,0,-1.5f);
            dian.drawSelf(gl);
        }
    }
}
